<?php 
global $wpdb;

if($sm != '') {
	//get the rows
	$sql = "SELECT * FROM ".$wpdb->prefix."hfr_url_craw WHERE sitemap = '".$sm."'";
	$row = $wpdb->get_row($sql);
}

$hfr_sitemap = $sm != '' ? $row->sitemap : '';
$hfr_link_selecter = $sm != '' ? $row->linkSelecter : '';
$hfr_link_selecter_js = $sm != '' ? $row->linkSelecterJs : '';
$hfr_title_selecter = $sm != '' ? $row->titleSelecter : '';
$hfr_content_selecter = $sm != '' ? $row->contentSelecter : '';
$hfr_remove_selecter = $sm != '' ? $row->removeSelecter : '';
$hfr_custom_selecter = $sm != '' ? $row->customSelecter : '';
$hfr_active_link_js = $sm != '' ? $row->activeLinkJs : 'no';
$hfr_active_content_js = $sm != '' ? $row->activeContentJs : 'no';
$hfr_time_craw = $sm != '' ? $row->timeCraw : 72;
$hfr_category = $sm != '' ? $row->category : '';
$hfr_type = $sm != '' ? $row->type : '';
$hfr_typelink = $sm != '' ? $row->typelink : 'nofollow';
$hfr_get_all = $sm != '' ? $row->getAll : 'no';
$hfr_source = $sm != '' ? $row->source : 'yes';
$hfr_sourcetype = $sm != '' ? $row->sourcetype : 'text';
$hfr_source_image = $sm != '' ? $row->source_image : 'source';
$hfr_remove_tag_a = $sm != '' ? $row->remove_tag_a : 'yes';
$hfr_share = $sm != '' ? $row->share : 'yes';

//Get all categories
$args = array(
	'type'                     => 'post',
	'hide_empty'               => 0,
); 
$categories = get_categories($args);
?>
<div class="hfr-body">
    <form method="post" action="admin.php?page=hfr_source_manager&act=submit_data&holder=hfr_sources" class="hfr-form-get-content">
		<div class="hfr-message-area">
			
		</div>
    	<div id="hfr-tabs">
            <ul class="hfr-tab-item">
                <li><a href="#hfr-tabs-1">Source's information</a></li>
                <li><a href="#hfr-tabs-2">Options</a></li>
            </ul>
            
            <!-- tab 1 - source's information -->
            <div id="hfr-tabs-1">
            	<p>Follow these steps bellow to get content. <a href="#" id="hfr-show-all-step">Click here to show all steps</a></p>
            	<div class="hfr-step step1">
                    <h2 class="hfr-step-name">Step 1</h2>
                    <div class="hfr-input-group clearafter">
                        <label for="hfr-sitemap">Sitemap</label>
                        <input type="text" id="hfr-sitemap" name="sitemap" value="<?=$hfr_sitemap ?>" />
                        <a id="hfr-check-sitemap" href="#" class="hfr-addon hfr-btn-blue">Check sitemap</a>
                        <img src="<?=HFR_PATH?>includes/assets/images/loading123.gif" class="hfr-loading" />   
                    </div>
                    <div class="hfr-step-instruction">
                        <ul>
                            <li>Enter the sitemap that you want to get content.</li>
                            <li>Click "Check Sitemap" to check if url is valid and supported.</li>
                        </ul>
                    </div>
                </div>
                <div class="hfr-step step2">
                    <h2 class="hfr-step-name">Step 2</h2>
                    <div id="hfr-link-selecter-group" class="hfr-input-group clearafter">
                        <label for="hfr-link-selecter">Link Selector</label>
                        <input type="text" id="hfr-link-selecter" name="linkSelecter" value="<?=$hfr_link_selecter ?>"/>
                        <a id="hfr-check-link-selector" href="#" class="hfr-addon hfr-btn-blue">Check information</a>
                        <img src="<?=HFR_PATH?>includes/assets/images/loading123.gif" class="hfr-loading" />
                    </div>
                    <div id="hfr-link-selecter-js">
                    	<span class="hfr-close-js">x</span>
                    	<div id="hfr-ace-link-selecter-js">
                    	<?php 
                    	if ($hfr_link_selecter_js == "") {
                    	?>
//Js function must return array of string link
function doGet(document)
{
	var data = new Array();
	data['link'] = new com.xty.Elements();
    data['link'] = document.select('a');
    return data;
}
						<?php } else { ?>
						<?=$hfr_link_selecter_js ?>
						<?php } ?>
						</div>
						<textarea name="linkSelecterJs" id='hfr-linkSelecterJs' style="display: none" disabled><?=$hfr_link_selecter_js?></textarea>
						<input type="hidden" name="activeLinkJs" id='hfr-activeLinkJs' value="<?=$hfr_active_link_js == "yes" ? $hfr_active_link_js : "no" ?>"/>
						<a id="hfr-check-link-selector-js" href="#" class="hfr-check-selector-js">
							<img src="<?=HFR_PATH?>includes/assets/images/loading123.gif" class="hfr-loading" />
							<span class="hfr-btn-blue">Check information</span>
						</a>
                    </div>
                    <div class="hfr-step-instruction">
                        <ul>
                            <li>Click "Check information" to verify the selector.</li>
                        </ul>
                        <p>Developer <a id="hfr-active-customer-link-js" href="#">click here</a>.</p>
                    </div>
                </div>
                <div class="hfr-step step3">
                    <h2 class="hfr-step-name">Step 3</h2>
                    <p class="hfr-sample-link"><span class="hfr-label-info">Sample link</span> <a href="#" id="hfr-example-link" target="_blank">http://www.designer-daily.com/awesome-ipad-wallpapers-11871</a></p>
                    <div class="hfr-input-group clearafter">
                        <label for="hfr-title-selecter">Title Selector</label>
                        <input type="text" id="hfr-title-selecter" name="titleSelecter" value="<?=$hfr_title_selecter ?>" />
                    </div>
                    <div class="hfr-input-group clearafter">
                        <label for="hfr-content-selecter">Content Selector</label>
                        <input type="text" id="hfr-content-selecter" name="contentSelecter" value="<?=$hfr_content_selecter ?>" />
                    </div>
                    <div class="hfr-input-group clearafter">
                        <label for="hfr-remove-selector">Remove Selector</label>
                        <input type="text" id="hfr-remove-selecter" name="removeSelecter" value="<?=$hfr_remove_selecter ?>" />
                    </div>
                    <div id="hfr-custom-selecter-js">
                    	<span class="hfr-close-js">x</span>
                    	<div id="hfr-ace-custom-selecter-js">
	                    	<?php 
	                    	if ($hfr_custom_selecter == "") {
	                    	?>
//Js function must return array of string link
function beforePost(document)
{
    var data = new Array();
    data['title'] = document.select('.title').text();
    
    document.select('.remove').remove();
    
    data['content'] =document.select('.content').html();
    
   return data;
} 
							<?php } else { ?>
							<?=$hfr_custom_selecter ?>
							<?php } ?>
						</div>
						<textarea name="customSelecter" id='hfr-customSelecter' style="display: none" disabled><?=$hfr_custom_selecter?></textarea>
						<input type="hidden" name="activeContentJs" id='hfr-activeContentJs' value="<?=$hfr_active_content_js == "yes" ? $hfr_active_content_js : "no" ?>"/>
                    </div>
                    <div class="hfr-step-instruction">
                        <ul>
                            <li>Type selector in 2 parameters "Title Selector" and "Content Selector" to get the title and content of the post.</li>
                            <li>
                                Type the selector in parameter "Remove Selector" to remove the part of content that you don't want to get.
                                <ul>
                                    <li>Each selector will be separated with the comma.</li>
                                    <li>Example : script, .addthis_toolbox, textarea</li>
                                </ul>
                            </li>
                            <li>Click "Preview" button to see the result.</li>
                        </ul>
                        <p>Developer <a id="hfr-active-custom-content-js" href="#">click here</a>.</p>
                    </div>
                    
                </div>
            </div>
            
            <!-- source option -->
            <div id="hfr-tabs-2">
            	<div class="hfr-options">
                
                	<!-- frequency -->
                    <div>
                        <p>Frequency : 12 hour</p>                        
                        <p class="hfr-text-warning">High value of frequency may cost you more credits. <br /> <strong>Recommended value : 6h - 24h.</strong></p>
                        <input type="hidden" name="timeCraw" value="<?=$hfr_time_craw; ?>">
                    </div>
                    
                    <hr />
                    
                    <!-- categories -->
                    <div class="clearafter hfr-options-categories">
                        <div>
                        	<div class="hfr-input-group clearafter">
                            	<input type="text" placeholder="Categories" name="category" id="hfr-category" value="<?=$hfr_category; ?>" readonly="readonly" />
                            </div>
                            <p class="hfr-text-info">Type categories, separated by comma.</p>
                            <p><span class="hfr-label-info">Example</span> category, category-1, category-2 ... </p>
                        </div>
                        <div>
                        	<div class="hfr-well">
                            	<div class="hfr-categoryListing">
                                	<ul>
	                                	<?php 
	                                	foreach($categories as $category) {
	                                	?>
                                        <li>
                                            <label class="checkbox"><input type="checkbox" class="checkcategory" name="cate" value="<?=$category->name?>"> <?=$category->name?> </label>
                                        </li>  
	                                    <?php 
	                                	}
	                                    ?>
                                    </ul>
                            	</div>
                            </div>
                        </div>
                    </div>
                    
                    <hr />
                    
                    <!-- source option -->
                    <div class="hfr-source-option">
                    	<div class="clearafter">
                        
                        	<!-- link -->
                        	<div>
                            	<div class="hfr-well">
                                	<h4>
                                    	Link
                                        <a class="hfr-btn-blue hfr-btn-small hfr-right" data-content="<p>
                                        	<a target='_blank' href='https://support.google.com/webmasters/answer/96569?hl=en'>Click here</a> for more information.</p>"
                                            data-placement="top"
                                            data-toggle="popover"
                                            data-container="body"
                                            data-html="true"
                                            data-original-title="Link">
          										info
        								</a>
                                    </h4>
                                    <hr />
                                    <label>
                                        <input type="radio" value="nofollow" <?=$hfr_typelink == "nofollow" ? "checked=\"checked\"" : ""?> name="typelink">
                                        Nofollow
                                    </label>
                                    <label>
                                        <input type="radio" value="follow" <?=$hfr_typelink == "follow" ? "checked=\"checked\"" : ""?> name="typelink">
                                        Follow
                                    </label>
                                </div>
                            </div>
                            
                            <!-- Get All Link  -->
                            <div>
                            	<div class="hfr-well">
                                	<h4>
                                    	Get All Link 
                                        <a
                                        	class="hfr-btn-blue hfr-btn-small hfr-right"
                                        	data-content="<p><strong>Yes</strong> : Get all posts that found.</p><p><strong>No</strong> : Get latest post.</p>"
                                            data-placement="top"
                                            data-toggle="popover"
                                            data-container="body"
                                            data-html="true"
                                            data-original-title="Get All Link">
          										info
        								</a>
                                    </h4>
                                    <hr />
                                    <label>
                                        <input type="radio" value="yes" <?=$hfr_get_all == "yes" ? "checked=\"checked\"" : ""?> name="getAll">
                                        Yes
                                    </label>
                                    <label>
                                        <input type="radio" value="no" <?=$hfr_get_all == "no" ? "checked=\"checked\"" : ""?> name="getAll">
                                        No
                                    </label>
                                </div>
                            </div>
                            
                            <!-- Source   -->
                            <div>
                            	<div class="hfr-well">
                                	<h4>
                                    	Source  
                                        <a
                                        	class="hfr-btn-blue hfr-btn-small hfr-right"
                                        	data-content="<p><strong>Yes</strong> : Reference will be remained on post. it will be displayed at the bottom of the post</p>"
                                            data-placement="top"
                                            data-toggle="popover"
                                            data-container="body"
                                            data-html="true"
                                            data-original-title="Source">
          										info
        								</a>
                                    </h4>
                                    <hr />
                                    <label>
                                        <input type="radio" value="yes" <?=$hfr_source == "yes" ? "checked=\"checked\"" : ""?> name="source">
                                        Yes
                                    </label>
                                    <label>
                                        <input type="radio" value="no" <?=$hfr_source == "no" ? "checked=\"checked\"" : ""?> name="source">
                                        No
                                    </label>
                                </div>
                            </div>
                        </div>
                        
                        <div class="clearafter">
                        
                        	<!-- Source Type  -->
                        	<div>
                            	<div class="hfr-well">
                                	<h4>
                                    	Source Type
                                        <a
                                        	class="hfr-btn-blue hfr-btn-small hfr-right"
                                        	data-content="<p>The format of source when display.</p><p>(display as Text or <a href='#'>Link</a>)</p>"
                                            data-placement="top"
                                            data-toggle="popover"
                                            data-container="body"
                                            data-html="true"
                                            data-original-title="Source Type">
          										info
        								</a>
                                    </h4>
                                    <hr />
                                    <label>
                                        <input type="radio" value="text" <?=$hfr_sourcetype == "text" ? "checked=\"checked\"" : ""?> name="sourcetype">
                                        Text
                                    </label>
                                    <label>
                                        <input type="radio" value="link" <?=$hfr_sourcetype == "link" ? "checked=\"checked\"" : ""?> name="sourcetype">
                                        Link
                                    </label>
                                </div>
                            </div>
                            
                            <!-- Source Image  -->
                            <div>
                            	<div class="hfr-well">
                                	<h4>
                                    	Source Image
                                        <a
                                        	class="hfr-btn-blue hfr-btn-small hfr-right"
                                        	data-content="<p>The place to store images.</p><p>Original: Treat image source as link.</p><p>CDN : images will be stored at google.</p>"
                                            data-placement="top"
                                            data-toggle="popover"
                                            data-container="body"
                                            data-html="true"
                                            data-original-title="Source Image">
          										info
        								</a>
                                    </h4>
                                    <hr />
                                    <label>
                                        <input type="radio" value="source" <?=$hfr_source_image == "source" ? "checked=\"checked\"" : ""?> name="source_image">
                                        Original
                                    </label>
                                    <label>
                                        <input type="radio" value="cdn" <?=$hfr_source_image == "cdn" ? "checked=\"checked\"" : ""?> name="source_image">
                                        CDN
                                    </label>
                                </div>
                            </div>
                            
                            <!-- Source   -->
                            <div>
                            	<div class="hfr-well">
                                	<h4>
                                    	Remove tag &lt;a&gt;
                                        <a
                                        	class="hfr-btn-blue hfr-btn-small hfr-right"
                                        	data-content="<p>Remove tag < a > in article</p>"
                                            data-placement="top"
                                            data-toggle="popover"
                                            data-container="body"
                                            data-html="true"
                                            data-original-title="Remove tag < a >">
          										info
        								</a>
                                    </h4>
                                    <hr />
                                    <label>
                                        <input type="radio" value="yes" <?=$hfr_remove_tag_a == "yes" ? "checked=\"checked\"" : ""?> name="remove_tag_a">
                                        Yes
                                    </label>
                                    <label>
                                        <input type="radio" value="no" <?=$hfr_remove_tag_a == "no" ? "checked=\"checked\"" : ""?> name="remove_tag_a">
                                        No
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>                    
                </div>
            </div>
        </div>
        
        <div class="hfr-panel-btn">
        	<hr />
	        <p>Click Preview button to check to be ok before click Add source</p>
	        
	        <!-- Button trigger modal -->
	        <a href="#" class="hfr-btn-light" data-toggle="modal" data-target="#myModal" id="hfr-preview">Preview</a>
	        <button type="submit" class="hfr-btn-blue btn-primary" disabled>Add Source</button>
        </div>
        
        <? if ($sm != "" ) {?>
		<input type="hidden" name="sm" value="<?=$sm?>" />
		<?php } ?>
		<input type="hidden" name="type" value="<?=$hfr_type?>" id="hfr-type">
    </form>
        
    <!-- Modal -->
    <div class="hfr-modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="hfr-modal-dialog">
            <div class="hfr-modal-content">
                <div class="hfr-modal-header">
                    <h3 class="hfr-modal-title" id="myModalLabel">Post Preview</h3>
                </div>
                <div class="hfr-modal-body">
                	<div class="hfr-content-center" id="hfr-effect-preview"><img src="<?=HFR_PATH?>includes/assets/images/loading123.gif" /></div>
                	<div class="hfr-content-preview">
                		
                	</div>                 
                </div>
                <div class="hfr-modal-footer">
                    <button type="button" class="hfr-btn-light" data-dismiss="modal">Close</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
</div>